﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using ApplicationBll;

namespace wallet.WebHandler
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class cardHandler : IHttpHandler
    {
        private Card _card = new Card();

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string result = string.Empty;
            switch (context.Request["action"])
            {
                case "GetNode":
                    result = GetNode(context.Request["node"]);
                    break;
                case "AddCard":
                    result = AddCard(context.Request["id"], context.Request["name"]);
                    break;
                default:
                    break;
            }
            context.Response.Write(result);
        }

        private string GetNode(string nodeID) 
        {
            return _card.GetJson(nodeID);
        }

        private string AddCard(string nodeID, string name)
        {
            string id = nodeID.Substring(13);
            try
            {
                _card.AddCardInfo(name, int.Parse(id));
                return "添加成功！";
            }
            catch (Exception)
            {

                return "添加失败！！！";
            }
            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
